.386
.586
.8087
.model flat, stdcall
option casemap :none
include \masm32\include\masm32rt.inc 
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\masm32.lib
.data
	ErrorSuma db "Error de overflow en suma", 0
	ErrorProducto db "Error de overflow en producto", 0
	_2_main DD 2
	_1_suma_main DD 1
	_a_suma_main DD ?
	_y_main DD ?
	_50_suma_main DD 50
	_x_main DD ?
	_a_imprimir_main DD ?
	_c_main DD ?
	_r_main DD ?
	_b_main DD ?
	_500_main DD 500
	_10_suma_main DD 10
	_return_de_suma_main DD 0
	_return_de_imprimir_main DD 0
	_a_main DD ?
	_x_imprimir_main DD ?
	_555_main DD 555
	_n123456_main DD -123456
	_2_suma_main DD 2
	_1_main DD 1
	_0_main DD 0
	_x_suma_main DD ?
	_500_imprimir_main DD 500
	_10_main DD 10


.code
	OVERFLOWPRODUCTO PROC
	JO Error_Producto
	RET
	OVERFLOWPRODUCTO ENDP
	
	OVERFLOWSUMA PROC
	JO Error_Suma
	RET
	OVERFLOWSUMA ENDP
	
	Error_Producto:
	print addr ErrorProducto,10,13
	inkey
	invoke ExitProcess,0
	
	Error_Suma:
	print addr ErrorSuma,10,13
	inkey
	invoke ExitProcess,0
imprimir PROC
	MOV ECX , _500_imprimir_main
	MOV _x_imprimir_main , ECX
	print ustr$( _a_imprimir_main),10,13
	print ustr$( _x_imprimir_main),10,13
	print ustr$( _b_main),10,13
	MOV ECX , _x_imprimir_main
	ADD ECX , _b_main
	CALL OVERFLOWSUMA
	MOV EBX , ECX
	MOV _return_de_imprimir_main, EBX
	RET
	MOV _return_de_imprimir_main, 0
	RET
	imprimir ENDP

suma PROC
	MOV ECX , _50_suma_main
	MOV _x_suma_main , ECX
	MOV ECX , _a_suma_main
	CMP ECX , _x_suma_main
	JBE label0
	MOV ECX , _a_suma_main
	ADD ECX , _10_suma_main
	CALL OVERFLOWSUMA
	MOV _a_suma_main , ECX
	JMP label1
label0:
	MOV ECX , _x_suma_main
	ADD ECX , _1_suma_main
	CALL OVERFLOWSUMA
	MOV _x_suma_main , ECX
	MOV EAX , _x_suma_main
	CDQ
	IDIV _2_suma_main
	MOV _a_suma_main , EAX
	print ustr$( _x_suma_main),10,13
label1:
	MOV _return_de_suma_main, 0
	RET
	suma ENDP

start:
	MOV ECX , _555_main
	MOV _y_main , ECX
	MOV ECX , _500_main
	MOV _b_main , ECX
	MOV ECX , _y_main
	MOV _a_imprimir_main , ECX
	CALL imprimir
	MOV ECX , _return_de_imprimir_main
	MOV _a_main , ECX
	print "lo siguiente debe dar mil (1000)",10,13
	print ustr$( _a_main),10,13
	MOV ECX , _555_main
	MOV _a_main , ECX
	MOV ECX , _10_main
	MOV _c_main , ECX
	MOV ECX , _10_main
	MOV _b_main , ECX
	MOV ECX , _10_main
	MOV _y_main , ECX
	MOV ECX , _10_main
	MOV _x_main , ECX
	MOV ECX , _y_main
	MOV _a_imprimir_main , ECX
	CALL imprimir
	MOV ECX , _return_de_imprimir_main
	MOV _y_main , ECX
	MOV ECX , _2_main
	MOV _x_main , ECX
	MOV ECX , _c_main
	MOV _a_suma_main , ECX
	CALL suma
	MOV ECX , _return_de_suma_main
	MOV _a_main , ECX
	print ustr$( _a_main),10,13
	MOV ECX , _0_main
	MOV _a_main , ECX
	MOV ECX , _a_main
	CMP ECX , _x_main
	JA label2
	print "if",10,13
	JMP label3
label2:
	print "else",10,13
label3:
	MOV ECX , _a_main
	ADD ECX , _1_main
	CALL OVERFLOWSUMA
	CMP ECX , _x_main
	JNE label4
	print "iguales",10,13
	JMP label5
label4:
	print "distintos",10,13
label5:
	MOV ECX , _a_main
	ADD ECX , _1_main
	CALL OVERFLOWSUMA
	CMP ECX , _x_main
	JE label6
	print "distintos",10,13
	JMP label7
label6:
	print "iguales",10,13
label7:
	MOV ECX , _1_main
	MOV _a_main , ECX
label8:
	MOV ECX , _a_main
	IMUL ECX , _2_main
	CALL OVERFLOWPRODUCTO
	MOV _a_main , ECX
	print "hola x 4",10,13
	MOV ECX , _a_main
	CMP ECX , _b_main
	JBE label8
	MOV ECX , _1_main
	MOV _a_main , ECX
label9:
	print "pepe2",10,13
	MOV ECX , _n123456_main
	ADD ECX , _b_main
	CALL OVERFLOWSUMA
	SUB ECX , _c_main
	MOV _x_main , ECX
label10:
	MOV ECX , _a_main
	IMUL ECX , _2_main
	CALL OVERFLOWPRODUCTO
	MOV _a_main , ECX
	print ustr$( _a_main),10,13
	MOV ECX , _a_main
	CMP ECX , _b_main
	JB label10
	MOV ECX , _a_main
	CMP ECX , _b_main
	JAE label11
	print "esto no se deberia ejecutar",10,13
	JMP label12
label11:
	print "esto si",10,13
label12:
	MOV ECX , _a_main
	CMP ECX , _b_main
	JB label9
	inkey
	invoke ExitProcess,0
end start
